import Web3 from "web3";
import VoteJSON from "../contract/Vote.json";//json文件
const useWeb3 = () => {
  const web3 = new Web3(
    Web3.givenProvider ||
    "wss://sepolia.infura.io/ws/v3/cb7e63cf28244e4499b4b6fb6162e746"//sepolia测试网络
  );
  const contractAddrress = "0x5bdE37CD33E1318338A205E837009255F0A4C648";//智能合约地址
  const voteContract = new web3.eth.Contract(VoteJSON.abi, contractAddrress);//智能合约实例
  //部署的时候一定记得修改

  const getAccount = async () => {//取账号方法
    const accounts = await web3.eth.requestAccounts();
    return accounts[0];//暴漏
  };

  return {//返回对象
    web3,
    voteContract,
    contractAddrress,
    getAccount,
  };
};

export default useWeb3;

//0xc77e4eae92784B9bAc743C3b95cBA504cccD85cf
//0xd9E29889EDf91B881608fa8B875Eb367953De4f5
//0xD2D084B0e5F44245b6678c05FF3147A0bB9cFC5c
//["0xc77e4eae92784B9bAc743C3b95cBA504cccD85cf","0xd9E29889EDf91B881608fa8B875Eb367953De4f5","0xD2D084B0e5F44245b6678c05FF3147A0bB9cFC5c"]